

public class SellTicket1 extends Thread{
    private static int ticket = 100;
    @Override
    public void run() {
        while(true){
            if(ticket <= 0){
                System.out.println("售罄！");
                break;
            }

            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("当前窗口："+Thread.currentThread().getName() + "购票成功，当前剩余票数："+ (--ticket));
        }
    }
}
